package com.zrrd.mq.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.QueueBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author WanJl
 * @version 1.0
 * @title BindingConfigs
 * @description
 * @create 2024/7/20
 */
//@Configuration
public class BindingConfigs {


    // 普通队列
    @Bean
    public Queue simpleQueue(){
        return new Queue("camq.simple.queue", true);
    }
    //声明存储死信的队列 dl.queue
    @Bean
    public Queue dlQueue(){
        return QueueBuilder.durable("dl.queue") // 指定队列名称，并持久化
                .deadLetterExchange("dl.direct") //dl:dead letter 指定死信交换机
                .build();
    }
    // 声明死信交换机 dl.direct
    @Bean
    public DirectExchange dlExchange(){
        return new DirectExchange("dl.direct", true, false);
    }
    // 将死信队列 与 死信交换机绑定
    @Bean
    public Binding dlBinding(){
        return BindingBuilder.bind(dlQueue()).to(dlExchange()).with("dl");
    }
}
